package com.nginx.web.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nginx.web.domain.LocationInfoQo;
import com.nginx.web.entity.LocationInfo;
import com.nginx.web.mapper.LocationInfoMapper;
import com.nginx.web.service.LocationInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyc
 * @since 2025-01-15
 */
@Service
public class LocationInfoServiceImpl extends ServiceImpl<LocationInfoMapper, LocationInfo> implements LocationInfoService {

    public Page<LocationInfo> listLocationInfo(LocationInfoQo qo) {
        Page<LocationInfo> page = new Page<>(qo.getPage() , qo.getLimit());
        LambdaQueryWrapper<LocationInfo> wrapper = Wrappers.lambdaQuery(LocationInfo.class);
        wrapper.like(StrUtil.isNotEmpty(qo.getUrl()), LocationInfo::getUrl , qo.getUrl() );
        wrapper.eq(qo.getIsEnable() != null , LocationInfo::getIsEnable , qo.getIsEnable());
        wrapper.eq(qo.getListen() != null, LocationInfo::getListen , qo.getListen() );
        wrapper.orderByAsc(LocationInfo::getListen);
        page(page , wrapper);
        return page;
    }

    public void updateLocationInfo(LocationInfo locationInfo) {
        updateById(locationInfo);
    }
}
